package com.baidu.controller;

import com.baidu.entity.ProjectClassEntity;
import com.baidu.service.impl.ProjectClassServiceImpl;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ProjectClassController {

    public void  run() throws IOException {
//        ProjectClassEntity res = selectProClassById(16L);
//        List<ProjectClassEntity> res = selectProClassList();
        List<ProjectClassEntity> res = selectProClassAndStuList();
//        System.out.println(res.toString());

//        System.out.println(updateProClassById(26L));;
//        System.out.println(deleteProClassById());
    }

    // vue: api/info/:userId
    // http://baidu.com/api/info/{idddd}?id=26&name=jerry
    // http://baidu.com/api/info/26?id=26&name=jerry
    // api/info/{id} ==> api/info//id=26 X api/info?id=26 X
    public ProjectClassEntity selectProClassById(Long id) {

         return new ProjectClassServiceImpl().selectProClassById(id);

         // 等价于以下代码
//        ProjectClassServiceImpl projectClassService = new ProjectClassServiceImpl();
//        ProjectClassEntity res = projectClassService.selectProClassById();
//
//        return res;
    }

    public List<ProjectClassEntity> selectProClassList() {
        ProjectClassEntity entity = new ProjectClassEntity();

//        entity.setId(26L);
        entity.setName("");
        Map<String, Object> map = new HashMap<>();
        map.put("beginCreateDate", "2024-01-07");
        map.put("endCreateDate", "2024-01-11");
        entity.setParams(map);
        return new ProjectClassServiceImpl().selectProClassList(entity);
    }

    public List<ProjectClassEntity> selectProClassAndStuList() {
        ProjectClassEntity entity = new ProjectClassEntity();

//        entity.setId(26L);
        entity.setName("");
        Map<String, Object> map = new HashMap<>();
//        map.put("beginCreateDate", "2024-01-07");
//        map.put("endCreateDate", "2024-01-11");
        entity.setParams(map);
        return new ProjectClassServiceImpl().selectProClassAndStuList(entity);
    }

    public int updateProClassById(Long id) throws IOException {
        return new ProjectClassServiceImpl().updateProClassById(id);
    }

    // 批量删除
    public int deleteProClassById() throws IOException {
        int[] arr = {111, 222,  16, 26};
        return new ProjectClassServiceImpl().deleteProClassById(arr);
    }
}
